import java.util.Stack;

public class MinStack {

    Stack<Integer> stack = new Stack<>();
    Stack<Integer> minStack = new Stack<>();
    public MinStack() {

    }

    public void push(int val) {
        stack.push(val);
        if(minStack.empty()){
            minStack.push(val);
        }else {
            int peekVal = stack.peek();
            if(peekVal <= minStack.peek()){
                minStack.push(val);
            }
        }
    }

    public void pop() {
        if(stack.empty()){
            return;
        }
        int popVal = stack.pop();
        if(popVal == minStack.peek()){
            minStack.pop();
        }
    }

    public int top() {
        if(stack.empty()){
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        if(stack.empty()){
            return -1;
        }

        return minStack.peek();
    }
}
